﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CommonType;
using DAL;
namespace BLL
{
    public class News
    {
        DAL.News news = new DAL.News();
        DAL.Comment comment = new Comment();
        public List<ArticalPiece>getLatestNews(int number)
        {
            return(news.GetLatest(number));
        }
	    public ArticalPiece getNewsByID(int ID)
        {
            return(news.Get(ID));
            
        }
	    public bool editNewsByID(int ID,ArticalPiece a)
        {
            //ArticalPiece a;
            news.Edit(ID,a);
            return true;
        }
	    public bool deleteNewsByID(int ID)
        {
            news.Delete(ID);
            return true;
        }
        public bool addComment(int articalID, string authorID, string content)
        {
            CommentPiece a = new CommentPiece();
            a.newsID = articalID;
            a.authorID = authorID;
            a.content = content;
            a.publishTime = DateTime.Now;
            comment.Add(a);
            return true;
        }
        public bool deleteCommentByID(int ID)
        {
            return comment.Delete(ID);
        }
    }
    public class Message
    {

        DAL.Message message = new DAL.Message();
	    public List<MessagePiece>getLatestMessage(int number)
        {
          // Message.List<MessagePiece> GetComment(n);
            return (message.GetComment(number));
        }
	    public MessagePiece getMessageByID(int ID)
        {
            return(message.Get(ID));
        }
	    public bool addMessage(string Author, string Content)
        {
            MessagePiece a = new MessagePiece();
            a.authorID = Author;
            a.content = Content;
            message.Add(a);
            return true;
        }
	    public bool deleteMessageByID(int ID)
        {
            return(message.Delete(ID));
        }
    }
    public class ManageUser
    {
        DAL.User user = new DAL.User();
	    public bool AddUser(int type, string name, string pass)
        {
            UserInfo a = new UserInfo();
            a.userType = type;
            a.userName = name;
            a.pass = pass;
            user.Add(a);
            return (true);
        }
	    public bool editUser(UserInfo oui)
        {
            long a = oui.ID  ;
            user.Edit(a, oui);
            return (true);
        }
	    public bool deleteUser(int ID)
        {
            user.Delete(ID);
            return (true);
        }
        public bool changeUserType(long ID, int userType)
        {
            UserInfo us = user.GetInfo(ID); 
            us.userType = userType;
            user.Edit(ID,us);
            return(true);

        }
    }
}
